package com.luxury.adpter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.luxury.R;
import com.luxury.bean.KuDaShiBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ironGe on 2016/12/17.
 */

public class KuDaShiRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    @BindView(R.id.tv_right_price_kuDaShi)
    TextView tvRightPriceKuDaShi;
    private Context mContext = null;
    private List<KuDaShiBean.TopickusBean> mList = null;

    public KuDaShiRecyclerAdapter(Context mContext, List<KuDaShiBean.TopickusBean> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_kudashi, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MyViewHolder) {
            KuDaShiBean.TopickusBean topickusBean = mList.get(position);
            //最上边的大图
            Glide.with(mContext).load(topickusBean.getImgurl()).into(((MyViewHolder) holder)
                    .ivBigPicKuDaShi);
            //下边3个集合
            List<KuDaShiBean.TopickusBean.ItemsBean> items = topickusBean.getItems();
            //左侧
            Glide.with(mContext).load(items.get(0).getSkuImgurl()).into(((MyViewHolder) holder)
                    .ivLeftKuDaShi);
            ((MyViewHolder) holder).tvLeftNameKuDaShi.setText(items.get(0).getSkuLinkName());
            ((MyViewHolder) holder).tvLeftPriceKuDaShi.setText("￥" + items.get(0).getPrice());
            //中间
            Glide.with(mContext).load(items.get(1).getSkuImgurl()).into(((MyViewHolder) holder).ivMiddleKuDaShi);
            ((MyViewHolder) holder).tvMiddleNameKuDaShi.setText(items.get(1).getSkuLinkName());
            ((MyViewHolder) holder).tvMiddlePriceKuDaShi.setText("￥" + items.get(1).getPrice());
            //右侧
            Glide.with(mContext).load(items.get(1).getSkuImgurl()).into(((MyViewHolder) holder).ivRightKuDaShi);
            ((MyViewHolder) holder).tvRightNameKuDaShi.setText(items.get(2).getSkuLinkName());
            ((MyViewHolder) holder).tvRightPriceKuDaShi.setText("￥" + items.get(2).getPrice());

        }
    }

    @Override
    public int getItemCount() {
        return mList.size();
        //        return 10;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_bigPic_kuDaShi)
        ImageView ivBigPicKuDaShi;
        @BindView(R.id.iv_left_kuDaShi)
        ImageView ivLeftKuDaShi;
        @BindView(R.id.tv_left_name_kuDaShi)
        TextView tvLeftNameKuDaShi;
        @BindView(R.id.tv_left_price_kuDaShi)
        TextView tvLeftPriceKuDaShi;
        @BindView(R.id.iv_middle_kuDaShi)
        ImageView ivMiddleKuDaShi;
        @BindView(R.id.tv_middle_name_kuDaShi)
        TextView tvMiddleNameKuDaShi;
        @BindView(R.id.tv_middle_price_kuDaShi)
        TextView tvMiddlePriceKuDaShi;
        @BindView(R.id.iv_right_kuDaShi)
        ImageView ivRightKuDaShi;
        @BindView(R.id.tv_right_name_kuDaShi)
        TextView tvRightNameKuDaShi;
        @BindView(R.id.tv_right_price_kuDaShi)
        TextView tvRightPriceKuDaShi;

        MyViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
